﻿
namespace Sissonix.ExtRest
{

    static class StringExtensions
    {
        public const string PATHDELIM = @"/";
        public const string WRONGDELIM = @"\";

        public static string FixPath(this string s)
        {
            return s.FixDelims().StripLastDelims();
        }

        public static string StripLastDelims(this string s)
        {
            string rslt = s;
            while (rslt.EndsWith(PATHDELIM) || rslt.EndsWith(WRONGDELIM))
                rslt = rslt.Remove(rslt.Length-1);

            return rslt;
        }
        
        public static string StripFirstDelims(this string s)
        {
            string rslt = s;
            while (rslt.StartsWith(PATHDELIM) || rslt.StartsWith(WRONGDELIM))
                rslt = rslt.Remove(0,1);

            return rslt;
        }

        public static string StripFirstLastDelims(this string s)
        {
            return s.StripFirstDelims().StripLastDelims();
        }

        public static string FixDelims(this string s)
        {
            return s.Replace(WRONGDELIM, PATHDELIM);
        }

    }
}
